<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      canvas {
        border: 1px solid #ccc;
        margin-right: 5px;
      }
    </style>
  </head>
  <body>
    <script>
      

       (()=>{
        const canvas = document.createElement("canvas");
        canvas.width = 400;
        canvas.height = 400;
        document.body.append(canvas);

        const ctx = canvas.getContext("2d");


        //变化坐标系
        ctx.transform(1,0,0,1,100,100);

        //绘制坐标系
        {
          ctx.beginPath();
          ctx.moveTo(-400,0);
          ctx.lineTo(400,0);
          ctx.moveTo(0,-400);
          ctx.lineTo(0,400);
          ctx.stroke();

          ctx.beginPath();
          ctx.arc(0,0,6,0,Math.PI*2) ;
          ctx.fill();

          for(let i=-400;i<=400;i+=10){
            ctx.beginPath();
            ctx.moveTo(i,-5);
            ctx.lineTo(i,5);
            ctx.stroke();

            ctx.beginPath();
            ctx.moveTo(-5,i);
            ctx.lineTo(5,i);
            ctx.stroke();
          }
        }
        
        //坐标系中绘制图形

       })();

       (()=>{
        const canvas = document.createElement("canvas");
        canvas.width = 400;
        canvas.height = 400;
        document.body.append(canvas);

        const ctx = canvas.getContext("2d");


        //变化坐标系
        ctx.transform(2,0,0,0.5,0,0);

        //绘制坐标系
        {
          ctx.beginPath();
          ctx.moveTo(-400,0);
          ctx.lineTo(400,0);
          ctx.moveTo(0,-400);
          ctx.lineTo(0,400);
          ctx.stroke();

          ctx.beginPath();
          ctx.arc(0,0,6,0,Math.PI*2) ;
          ctx.fill();

          for(let i=-400;i<=400;i+=10){
            ctx.beginPath();
            ctx.moveTo(i,-5);
            ctx.lineTo(i,5);
            ctx.stroke();

            ctx.beginPath();
            ctx.moveTo(-5,i);
            ctx.lineTo(5,i);
            ctx.stroke();
          }
        }
        
        //坐标系中绘制图形

       })();

       (()=>{
        const canvas = document.createElement("canvas");
        canvas.width = 400;
        canvas.height = 400;
        document.body.append(canvas);

        const ctx = canvas.getContext("2d");


       

        //绘制坐标系
        {
          ctx.beginPath();
          ctx.moveTo(-400,0);
          ctx.lineTo(400,0);
          ctx.moveTo(0,-400);
          ctx.lineTo(0,400);
          ctx.stroke();

          ctx.beginPath();
          ctx.arc(0,0,6,0,Math.PI*2) ;
          ctx.fill();

          for(let i=-400;i<=400;i+=10){
            ctx.beginPath();
            ctx.moveTo(i,-5);
            ctx.lineTo(i,5);
            ctx.stroke();

            ctx.beginPath();
            ctx.moveTo(-5,i);
            ctx.lineTo(5,i);
            ctx.stroke();
          }
        }
        
        ctx.strokeStyle = '#f00';
        ctx.setLineDash([10]);
        ctx.strokeRect(0,0,200,100);

        //变化坐标系
        ctx.transform(1,0,Math.tan(30 * Math.PI/180),1,0,0);

        //坐标系中绘制图形
        ctx.fillStyle = 'rgba(0,0,0,0.5)'
        ctx.fillRect(0,0,200,100);

       })();

       (()=>{
        const canvas = document.createElement("canvas");
        canvas.width = 400;
        canvas.height = 400;
        document.body.append(canvas);

        const ctx = canvas.getContext("2d");


        //变化坐标系
        ctx.transform(Math.cos(45*Math.PI/180),Math.sin(45*Math.PI/180),-Math.sin(45*Math.PI/180),Math.cos(45*Math.PI/180),0,0);

        //绘制坐标系
        {
          ctx.beginPath();
          ctx.moveTo(-400,0);
          ctx.lineTo(400,0);
          ctx.moveTo(0,-400);
          ctx.lineTo(0,400);
          ctx.stroke();

          ctx.beginPath();
          ctx.arc(0,0,6,0,Math.PI*2) ;
          ctx.fill();

          for(let i=-400;i<=400;i+=10){
            ctx.beginPath();
            ctx.moveTo(i,-5);
            ctx.lineTo(i,5);
            ctx.stroke();

            ctx.beginPath();
            ctx.moveTo(-5,i);
            ctx.lineTo(5,i);
            ctx.stroke();
          }
        }
        


       })();
    </script>

  </body>
</html>
